package com.zl.basis.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class StringUtil {
    public static boolean isEmpty(String s) {
        return null == s || s.isEmpty();
    }

    /**
     * 检查指定的字符串列表是否不为空。
     */
    public static boolean areNotEmpty(String... values) {
        boolean result = true;
        if (values == null || values.length == 0) {
            result = false;
        } else {
            for (String value : values) {
                result &= !isEmpty(value);
            }
        }
        return result;
    }

    public static Integer stringToInt(String value) {
        Integer result = null;
        if (!isEmpty(value)) {
            try {
                result = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    public static <T> List<T> stringSetToList(Set<T> values) {
        List<T> list = null;
        if (null != values && values.size() > 0) {
            list = new ArrayList<>(values);
        }
        return list;
    }

    public static <T> Set<T> stringListToSet(List<T> values) {
        Set<T> sets = null;
        if (null != values && values.size() > 0) {
            sets = new HashSet<>(values);
        }
        return sets;
    }
}
